package com.mzj.saas.mservice.sys.service;

import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.commons.vo.redis.TokenRedisVo;
import com.mzj.saas.mservice.bill.entity.HouseContractPayTime;
import com.mzj.saas.mservice.bill.repository.HouseContractPayTimeRepository;
import com.mzj.saas.mservice.bill.vo.HouseContractPayTimeVO;
import com.mzj.saas.redis.RedisService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class HouseContractPayTimeService {
    private Logger LOG = LoggerFactory.getLogger(HouseContractPayTimeService.class);

    @Autowired
    private HouseContractPayTimeRepository houseContractPayTimeRepository;
    @Autowired
    private RedisService redisService;

    public ResultBean<Object> list(String accessToken){
        LOG.info(" houseContractPayTimeService  list  accessToken = {}",accessToken);
        TokenRedisVo tokenRedisVo = redisService.findTokenVo(accessToken);

        HouseContractPayTime houseContractPayTime = houseContractPayTimeRepository.findByOrgId(tokenRedisVo.getEnterpriseId());

        return ResultBean.successfulResult(houseContractPayTime);
    }

    public ResultBean<Object> setting(String accessToken, HouseContractPayTimeVO vo){
        LOG.info(" houseContractPayTimeService   setting  accessToken={}, HouseContractPayTimeVO={}",accessToken,vo.toString());

        if(vo.getTime() == null){
            return ResultBean.failedResultWithMsg("时效天数为空");
        }

        TokenRedisVo tokenRedisVo = redisService.findTokenVo(accessToken);
        HouseContractPayTime houseContractPayTime =new HouseContractPayTime();

        BeanUtils.copyProperties(vo,houseContractPayTime);
        houseContractPayTime.setOrgId(tokenRedisVo.getEnterpriseId());

        houseContractPayTimeRepository.save(houseContractPayTime);

        return ResultBean.successfulResult(null);
    }


}
